package com.fc.async;

import com.fc.async.MailTask;
import com.fc.async.TestMyThread;
import com.fc.async.springTest;
import com.fc.mapper.UserMapper;
import com.fc.model.User;
import com.fc.util.MyConstant;
import com.fc.util.MyUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User :zhaiyujin
 * Date :2017/5/23
 * Time :17:59
 * Msg  :
 */
@Controller
public class test {

    @Test
        public void test() {
        ThreadPoolTaskExecutor taskExecutor  = springTest.getContext().getBean("taskExecutor",ThreadPoolTaskExecutor.class);
        /*for(int i=0;i<100000;i++){
            System.out.println("开始执行任务：" + i);

            taskExecutor.execute(new TestMyThread("zhaiyujin",i));

        }*/
        taskExecutor.execute(new TestMyThread("zhaiyujin",3));
        System.out.println("11111111111111111111111");
    }

    @Test
    public void sendmail1(){
        ThreadPoolTaskExecutor taskExecutor  =springTest.getContext().getBean("taskExecutor",ThreadPoolTaskExecutor.class);
        JavaMailSenderImpl javaMailSender= springTest.getContext().getBean("javaMailSender",JavaMailSenderImpl.class);
       new MailTask("1231637", "568941179@qq.com", javaMailSender, 1).run();
    }
    @Test
    public void testmd5(){
       // String test=MyUtil.md5("123321");
       // MyUtil.createRandomCode();
        System.out.println( String.valueOf(5)+4);

    }

   @Test
   public void regest(){
       User user = new User();
       user.setEmail(MyUtil.createRandomCode().substring(0,8)+"@qq.com");
       user.setPassword(MyUtil.md5("123321"));
       // 构造user，设置未激活
       String activateCode = MyUtil.createRandomCode();
       user.setActivationCode("123123");
       user.setJoinTime(new Date().getTime());

       user.setUsername("zhaiyujin");
       user.setAvatarUrl(MyConstant.QINIU_IMAGE_URL + "head.jpg");
       UserMapper userMapper=springTest.getContext().getBean("userMapper",UserMapper.class);

       // 向数据库插入记录
       userMapper.insertUser(user);
       System.out.println("现在我们获取到的id:"+user.getUserId());

   }

    public static void main(String[] args) {
        ThreadPoolTaskExecutor taskExecutor  =springTest.getContext().getBean("taskExecutor",ThreadPoolTaskExecutor.class);
        JavaMailSenderImpl javaMailSender= springTest.getContext().getBean("javaMailSender",JavaMailSenderImpl.class);
        for (int i=0;i<10;i++){
        MailTask dw = new MailTask("1231637", "565464189@qq.com", javaMailSender, 1);

        taskExecutor.execute(dw);}
    }

}
